/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.classloader.mutator;

import picounit.features.base.AbstractAggregateExtension;

public class AggregateClassMutator extends AbstractAggregateExtension<ClassMutator>
	implements ClassMutator {

	public AggregateClassMutator() {
		super(ClassMutator.class);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// AggregateExtension methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public ClassMutator get() {
		return this;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// ClassMutator methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public boolean shouldMutate(String className) {
		for (ClassMutator classMutator : extensions()) {
			if (classMutator.shouldMutate(className)) {
				return true;
			}
		}

		return false;
	}

	public byte[] mutate(String className, byte[] byteCode) {
		byte[] mutatedByteCode = byteCode;

		for (ClassMutator classMutator : extensions()) {
			if (classMutator.shouldMutate(className)) {
				mutatedByteCode = classMutator.mutate(className, mutatedByteCode);
			}
		}

		return mutatedByteCode;
	}
}
